<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>管理招聘信息</title>
    <link rel="stylesheet" href="../../plugins/element-ui/theme-chalk/index.css"/>
    <script src="../../js/vue.js" charset="utf-8"></script>
    <script src="../../plugins/element-ui/index.js" charset="utf-8"></script>
    <!-- 引入axios -->
    <script src="../../plugins/axios.min.js"></script>

    <script src="../../js/request.js"></script>
    <script src="../../js/recruit.js"></script>

    <style name="table">
        .el-table .warning-row {
            background: oldlace;
        }

        .el-table .success-row {
            background: #f0f9eb;
        }
    </style>
</head>
<body>

<div id="container">
    <!--搜索表单    -->
    <el-form :inline="true" :model="recruitMessage" class="demo-form-inline">
        <el-form-item label="薪资">
            <el-select v-model="recruitMessage.salary" placeholder="薪资范围">
                <el-option label="5000-9000" value="base"><el-button type="primary" @click="salaryControl(5000,9000)">5000-9000</el-button></el-option>
                <el-option label="9001-15000" value="pro"><el-button type="primary" @click="salaryControl(9000,15000)">9001-15000</el-button></el-option>
                <el-option label="15001以上" value="max"><el-button type="primary" @click="salaryControl(15001,100000)">15001以上</el-button></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="岗位名">
            <el-input v-model="recruitMessage.name" placeholder="岗位名"></el-input>
        </el-form-item>
        <el-form-item label="编号">
            <el-input v-model="recruitMessage.id" placeholder="岗位编号"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
    </el-form>

    <!--功能按钮-->
    <el-row>
        <el-button type="primary" plain @click="recruitMessage.addDialogFormVisible = true">新增</el-button>
    </el-row>

    <!--新增框表单-->
    <el-dialog title="招聘信息" :visible.sync="recruitMessage.addDialogFormVisible" append-to-body>
        <el-form :model="recruitMessage">
            <el-form-item label="岗位名" :label-width="formLabelWidth">
                <el-input v-model="recruitMessage.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="岗位编号" :label-width="formLabelWidth">
                <el-input v-model="recruitMessage.id" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="年龄限制" :label-width="formLabelWidth">
                <el-input v-model="recruitMessage.ageLimit" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="学历要求" :label-width="formLabelWidth">
               <el-input v-model="recruitMessage.academicRequirements" autocomplete="off"></el-input>
           </el-form-item>
            <el-form-item label="技术栈" :label-width="formLabelWidth">
                <el-input v-model="recruitMessage.technologyStack" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="薪资" :label-width="formLabelWidth">
                <el-input v-model="recruitMessage.salary" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="岗位数" :label-width="formLabelWidth">
                <el-input v-model="recruitMessage.spareNumber" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="recruitMessage.addDialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="addRecruit">立即创建</el-button>
        </div>
    </el-dialog>


    <!--table表格 -->
    <template>
        <el-table
                :data="tableData"
                style="width: 100%"
                :row-class-name="tableRowClassName">
            <el-table-column
                    prop="name"
                    label="岗位名"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="id"
                    label="岗位编号"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="ageLimit"
                    label="年龄要求"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="academicRequirements"
                    label="学历要求"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="technologyStack"
                    label="技术栈"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="salary"
                    label="薪资"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="spareNumber"
                    label="剩余"
                    align="center">
            </el-table-column>
            <el-table-column
                    align="center"
                    label="操作">
                <!--修改对话框表单-->
                <template slot-scope="scope">
                    <el-button type="primary" @click="Update(scope.row)">修改</el-button>
                    <el-button type="danger" @click="Delete(scope.row.id)">删除</el-button>
                    <!--     对话框               -->
                    <el-dialog title="修改账户信息" :visible.sync="recruitMessage.updateDialogFormVisible">
                        <el-form :model="recruitMessage">
                            <el-form-item label="岗位名" :label-width="formLabelWidth">
                                <el-input v-model="recruitMessage.name" autocomplete="off"></el-input>
                            </el-form-item>
                            <el-form-item label="岗位编号" :label-width="formLabelWidth">
                                <el-input v-model="recruitMessage.id" autocomplete="off"></el-input>
                            </el-form-item>
                            <el-form-item label="年龄限制" :label-width="formLabelWidth">
                                <el-input v-model="recruitMessage.ageLimit" autocomplete="off"></el-input>
                            </el-form-item>
                            <el-form-item label="学历要求" :label-width="formLabelWidth">
                                <el-input v-model="recruitMessage.academicRequirements" autocomplete="off"></el-input>
                            </el-form-item>
                            <el-form-item label="技术栈" :label-width="formLabelWidth">
                                <el-input v-model="recruitMessage.technologyStack" autocomplete="off"></el-input>
                            </el-form-item>
                            <el-form-item label="薪资" :label-width="formLabelWidth">
                                <el-input v-model="recruitMessage.salary" autocomplete="off"></el-input>
                            </el-form-item>
                        </el-form>
                        <div slot="footer" class="dialog-footer">
                            <el-button @click="recruitMessage.updateDialogFormVisible = false">取 消</el-button>
                            <el-button type="primary" @click="exit">立即修改</el-button>
                        </div>
                    </el-dialog>
                </template>
            </el-table-column>
        </el-table>
    </template>

</div>

<script>
    new Vue({
        el:"#container",
        methods: {
            //使不同行颜色不同
            tableRowClassName({row, rowIndex}) {
                if (rowIndex === 1) {
                    return 'warning-row';
                } else if (rowIndex === 3) {
                    return 'success-row';
                }
                return '';
            },

            //查询全部数据
            async selectAll(){
                this.employer.name=localStorage.getItem('user');
                this.recruitMessage.employerName=localStorage.getItem('user');
                await list(this.employer).then(res => {
                    if (String(res.code) === '1') {
                    this.tableData=res.data;
                } else {
                    this.$message.error(res.msg || '查询失败')
                }
            }).catch(err => {
        this.$message.error('请求出错了：' + err)
    })
    },

            //点击查询后执行
            async onSubmit() {
               queryRecruit(this.recruitMessage).then(res=> {
                    this.tableData=res.data;
                }).then(function (res) {
                       //判断响应数据是否为success
                       if(String(res.code) === "1"){
                           //提示消息
                           this.$message({
                               message: '查询成功！',
                               type: 'success'
                           })
                       }
            })
            },
            //添加数据
            addRecruit(){
                save(this.recruitMessage).then(res=> {
                    //判断响应数据是否为success
                    if(String(res.code) === "1"){
                        //隐藏表单
                        this.recruitMessage.addDialogFormVisible = false;
                        //重新查询所有，避免刷新
                        this.selectAll();
                        //提示消息
                        this.$message({
                            message: '添加账户成功！',
                            type: 'success'
                        });
                    }
                })
            },

            //删除
            Delete(id){
                this.recruitMessage.id=id;
                // 弹出确认提示框
                this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    deleteRecruit(this.recruitMessage).then(res => {
                        if (String(res.code) === "1") {
                            //重新查询所有，避免刷新
                            this.selectAll();
                            this.$message({
                                message: '删除岗位招聘信息成功！',
                                type: 'success'
                            });
                        } else {
                            this.$message.error({
                                message: '删除岗位招聘信息失败！',
                                type: 'success'
                            });
                        }
                    })
                }).catch(() => {
                    //用户点击取消按钮
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },

            Update(row){
                this.recruitMessage.id=row.id;
                this.recruitMessage.name = row.name
                this.recruitMessage.academicRequirements = row.academicRequirements;
                this.recruitMessage.ageLimit = row.ageLimit;
                this.recruitMessage.salary = row.salary;
                this.recruitMessage.spareNumber = row.spareNumber;
                this.recruitMessage.technologyStack = row.technologyStack;
                this.recruitMessage.updateDialogFormVisible = true
            },
            exit(){
                editRecruitMessage(this.recruitMessage).then(res => {
                    if (String(res.code)=== "1") {
                        this.$message.success('修改成功！')
                        this.recruitMessage.updateDialogFormVisible = false
                        this.selectAll();
                    } else {
                        this.$message.error(res.msg || '操作失败')
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
            },

        //薪资上下限控制
            salaryControl(minSalary,maxSalary){
            this.recruitMessage.maxSalary=maxSalary;
            this.recruitMessage.minSalary=minSalary;
        },
    },
        created() {
            this.selectAll();
        },
        data() {
            return {
                tableData: [],

                //岗位模型数据
                recruitMessage:{
                    employerName:"",
                    name: "",
                    id: "",
                    ageLimit:"",
                    academicRequirements:"",
                    technologyStack:"",
                    salary: "",
                    spareNumber:"",
                    maxSalary:'',
                    minSalary:'',
                    //默认对话框显示状态
                    addDialogFormVisible: false,
                    updateDialogFormVisible:false,
                },

                employer: {
                    name:"",
                    size:"",
                    address:"",
                    city:"",
                    phone:"",
                },
                formLabelWidth: '80px',

            }
        }
    })
</script>
</body>
</html>